package com.jzo2o.customer.controller.consumer;

import com.jzo2o.api.customer.dto.request.EvaluationSubmitReqDTO;
import com.jzo2o.api.customer.dto.request.InstitutionStaffPageQueryReqDTO;
import com.jzo2o.api.customer.dto.response.AddressBookResDTO;
import com.jzo2o.api.customer.dto.response.InstitutionStaffResDTO;
import com.jzo2o.common.model.PageResult;
import com.jzo2o.customer.model.domain.AddressBook;
import com.jzo2o.customer.model.dto.request.AddressBookPageQueryReqDTO;
import com.jzo2o.customer.model.dto.request.AddressBookUpsertReqDTO;
import com.jzo2o.customer.model.dto.response.BooleanResDTO;
import com.jzo2o.customer.service.IAddressBookService;
import com.jzo2o.mvc.utils.UserContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.github.pagehelper.page.PageMethod.startPage;

/**
 * <p>
 * 地址薄
 * </p>
 *
 * @author itcast
 * @since 2023-07-03
 */
@RestController("consumerAddressBookController")
@RequestMapping("/consumer/address-book")
@Api(tags = "用户端 - 用户地址相关接口")
public class AddressBookController{
    @Autowired
    private IAddressBookService addressBookService;

    @GetMapping("/defaultAddress")
    @ApiOperation("查询用户默认地址值")
    public AddressBookResDTO defaultAddress() {
        return addressBookService.defaultAddress();
    }

    @PostMapping
    @ApiOperation("新增地址簿")
    public void insertAddress(@RequestBody AddressBookUpsertReqDTO dto) {
        addressBookService.insertAddress(dto);
    }


    @GetMapping("/page")
    @ApiOperation("地址簿列表")
    public PageResult<AddressBook> addressPage(AddressBookPageQueryReqDTO dto) {
        return addressBookService.addressPage(dto);
    }


    @GetMapping("/{id}")
    @ApiOperation("地址簿详情")
    public AddressBook addressDetails(@PathVariable Long id) {
        return addressBookService.addressDetails(id);
    }

    @PutMapping("/{id}")
    @ApiOperation("地址簿编辑")
    public void updateAddress(@RequestBody AddressBookUpsertReqDTO dto,@PathVariable Long id) {
         addressBookService.updateAddress(dto,id);
    }

    @DeleteMapping("/batch")
    @ApiOperation("地址簿删除")
    public void batchDelete(@RequestBody List<Long> ids) {
        addressBookService.batchDelete(ids);
    }

    @PutMapping("/default")
    @ApiOperation("设置默认地址")
    public void defaultAddress(Long flag ,Long id) {
        addressBookService.defaultAddr(flag,id);
    }
}
